﻿// See https://aka.ms/new-console-template for more information
using static System.Console;
using TestList;


Title = "C#中List去重";

List<int> ints = new List<int>() { 1, 2, 2, 22, 2, 3, 4, 4, 4, 5, 6, 7, 8, 9 };
List<int> temps = ints.Distinct<int>().ToList();
foreach (var item in temps)
{
    WriteLine(item);
}


List<string> list = new List<string>() { "a", "b", "c", "d", "a", "b" };
List<string> tempList = list.Distinct<string>().ToList();
foreach (var item in tempList)
{
    WriteLine(item);
}


List<Person> listPerson = new List<Person>()
{
    new Person()
    {
        Id =1,Name ="chen",Age= 23
    },
    new Person()
    {
        Id =2,Name ="kai",Age= 22
    },
    new Person()
    {
        Id =3,Name ="buer",Age= 21
    },

};

//去重
List<Person> tempPersons = listPerson.Distinct<Person>(new TestComparer()).ToList();

foreach (Person per in tempPersons)
{
    WriteLine($"ID:{per.Id},name:{per.Name},age:{per.Age}");
}




ReadKey();